<?php
/**
 * 新闻公告管理
 * 
 * @author Lee <a605333742@gmail.com>
 * @time 2016-04-19
 */
namespace Home\Controller;

class NoticeController extends AllowController{
    /*
     * 构造函数
     *
     * @return  #
     */
    public function _initialize(){       
        parent::_initialize();
        $this->db_notice=D("Notice");
    }
    
    /*
     * 新闻公告列表
     * 
     * @return #
     */
    public function indexNews(){ 
        if(I("request.sign","",'code')){ 
            if(I("request.sign","",'code')==1){
                C("PAGE_JUMP_PARAM",1);
            }elseif(I("request.sign","",'code')==2){
                C("PAGE_JUMP_PARAM",2);
            }else if(I("request.sign","",'code')==3){
                C("PAGE_JUMP_PARAM",3);
            }else if(I("request.sign","",'code')==4){
                C("PAGE_JUMP_PARAM",4);
            }            
        }
        
        if(I("request.id","","code")){
            $id =I("request.id","","code");
        }
       
        A("Allow")->firstInfo($id);
        $where=array(
            "status"    =>1,
            "section_id"=>1,
            "top"       =>array("lt",session("top"))
        );
        if($id){
            $where['top']   =array("lt",session("top")+1);
            $where['id']    =array("neq",$id);
        }   
        if(C("PAGE_JUMP_PARAM")!=4){
            $where['sign']  =I("request.sign","",'code');
        }else{
            $where['sign']  =array("neq",'3');
        }
        $ord['top']         =desc;
        $ord['add_time']    =desc;
        $nInfo      =$this->db_notice->showList($where,$ord,5,1);
        $nList      =$nInfo['noticeList'];
        $pageList   =$nInfo['pageList'];
        //$enPage     =enPage($pageList);       
        $this->assign("pageList",$pageList);
        $this->assign("nList",$nList);
        $this->display();
    }
    
    /*
     * 新闻公告详情
     * 
     * @return  #
     */
    public function info(){
        $where=array(
            "id"        =>I("request.id","","code"),
            "status"    =>1
        );
        $info   =$this->db_notice->where($where)->find();
        $zanNum =D("Zambia")->where(array("group_id"=>I("request.id","","code")))->count();        
        $this->assign("zan",$zanNum);
        $this->assign("info",$info);
        $this->display();
    }
    
    /*
     * 点赞
     * 
     * @return #
     */
    public function ajaxZan(){
        $map['group_id']=I("request.group_id");
        $map['user_id'] =$_SESSION['home']['id'];
        if(D("Zambia")->where($map)->find()){
            echo FALSE;
        }else{
            if(D("Zambia")->add($map)){
                $zanCount   =D("Zambia")->where(array("group_id"=>$map['group_id']))->count();
                if($this->addDraw(0)){
                    echo $zanCount;
                }else{
                    echo FALSE;
                }                
            }else{
                echo FALSE;
            }
        }
    }
}
